﻿package cn.antscript.airCMS.display 
{
	import cn.antscript.airCMS.display.component.btnbase.AbstractIco;
	import cn.antscript.airCMS.display.component.btnbase.IcoBitmapdatas;
	import com.yahoo.astra.fl.controls.AudioPlayback;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author antscript
	 */
	public class MusicListener extends Sprite
	{
		
		private static var _instance:MusicListener;
		private var _player:AudioPlayback;
		private var _closeBtn:AbstractIco;
		
		
		
		public function MusicListener(privateClass:PrivateClass) 
		{
			
			_player = new AudioPlayback(this);
			
			
		}
		
		private function onClick(e:MouseEvent):void 
		{
			hide();
		}
		
		public static function getInstance():MusicListener {
			if (_instance == null) {
				_instance = new MusicListener(new PrivateClass);
			}
			return _instance;
		}
		
		public function play(url:String, container:DisplayObjectContainer):void {
			
			_closeBtn = new AbstractIco(IcoBitmapdatas.Delete, "返回", MusicListener.getInstance());
			_closeBtn.addEventListener(MouseEvent.CLICK, onClick);
			
			container.addChild(MusicListener.getInstance());	
			
			graphics.clear();
			graphics.beginFill(0x333333, 0.8);
			graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
			graphics.endFill();
			
			_player.x = (stage.stageWidth - _player.width) / 2;
			_player.y = (stage.stageHeight - _player.height) / 2;
			_player.loadMedia(url);
			
			
			_closeBtn.x = _player.x + _player.width+5;
			_closeBtn.y = _player.y + 3;
			_closeBtn.visible = true;
			
			
		}
		public function hide():void {
			
			_player.loadMedia("", false);
			
			this.parent.removeChild(this);
			
			_closeBtn.removeEventListener(MouseEvent.CLICK, onClick);
		}
		
		
		
		
		
	}

}

class PrivateClass {
	
}